package com.liu.spring.framework;

import com.liu.demo.AppConfig;
import com.liu.demo.UserInterface;
import com.liu.demo.UserService;
import com.liu.spring.framework.context.LiuApplicationContext;

import java.beans.Introspector;

/**
 * @description TODO
 * @author liuzq
 * @date 2024/2/6 13:04
 *
 * 1. 实现spring启动和扫描逻辑实现
 * 2. BeanDefinition对象
 * 3. spring依赖注入实现
 * 4. Aware回调实现
 * 5. 初始化机制
 * 6. BeanPostProcessor 实现
 * 7. AOP实现
 */
public class _Test {
    public static void main(String[] args) {
        LiuApplicationContext context = new LiuApplicationContext(AppConfig.class);

        UserInterface userService = (UserInterface) context.getBean("userService");

        System.out.println("================spring容器初始化完成===============");
        userService.test();
        System.out.println("================userServices实例===============");
        System.out.println(userService);

//        System.out.println( context.getBean("userService"));
//        System.out.println( context.getBean("userService"));
//        System.out.println( context.getBean("userService"));
//        System.out.println( context.getBean("orderService"));

//        reflect();
    }

    /**
     * 反射测试
     */
    private static void reflect() {
        Class<?> clazz = null;
        try {
            clazz = Class.forName("com.liu.demo.UserService");

            String simpleName = clazz.getSimpleName();
            UserService instance = (UserService)clazz.newInstance();

            System.out.println("instance:  " + instance);
            System.out.println("simpleName:  " + simpleName);

            // 大小写转换工具
            String beanName = Introspector.decapitalize(simpleName);

            System.out.println(beanName);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
